#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../utils/array.h"

void strs_deinit(void *pp)
{
    char *s = (char *)pp;
    printf("strs_deinit free(%s)\n", s);
    free(s);
}

int main()
{
    array_t *strs = array_init(strs_deinit);
    int len = 3;
    char *strings[3] = {0};
    for (int i = 0; i < len; i++)
    {
        char *s = malloc(7);
        if (s == NULL)
            continue;
        // "hero"
        sprintf(s, "hero$%d", i);
        printf("strs+ (%s) ptr:%p\n", s, s);
        array_add(strs, s);
        strings[i] = s;
    }
    for (int i = 0; i < strs->len; i++)
    {
        char *s = (char *)array_get(strs, i);
        printf("strs[%d]:%s\n", i, s);
    }
    printf("===========================\n");
    char *s = malloc(7);
    sprintf(s, "hero$%d", 9);
    array_insert(strs, 1, s);
    memset(s, 0, 7);
    sprintf(s, "hero$%d", 6);
    array_delete(strs, 1, 1);
    printf("===========================\n");
    // array_append1(strs, strings, 3);
    printf("===========================\n");
    for (int i = 0; i < strs->len; i++)
    {
        char *s = (char *)array_get(strs, i);
        printf("strs[%d]:%s\n", i, s);
    }
    array_deinit(&strs);
    return 0;
}